﻿using B.S.BaseData.Api.Write.Applicantion.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Entitys;
using MediatR;

namespace B.S.BaseData.Api.Write.Applicantion.CommandHandler.GoodsCommandHandler
{
    public class GoodsproductsImgDeleteCommandHandler : IRequestHandler<GoodsproductsImgDeleteCommand, APIResult<int>>
    {
        private readonly IBaseRepository<ImgInfo> _imgInfoRepository;
        public GoodsproductsImgDeleteCommandHandler(IBaseRepository<ImgInfo> imgInfoRepository)
        {
            _imgInfoRepository = imgInfoRepository;
        }
        public async Task<APIResult<int>> Handle(GoodsproductsImgDeleteCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            try
            {
                var list =await _imgInfoRepository.GetValues(x=>x.Id==request.Id);
                await _imgInfoRepository.Delete(list);
                result.Code = ApiEnum.Success;
                result.Msg = "图片删除成功";
                result.Data = 1;
                return await Task.FromResult(result);
            }
            catch (Exception)
            {
                result.Code = ApiEnum.Success;
                result.Msg = "图片删除失败";
                result.Data = 1;
                return await Task.FromResult(result);
            }
        }
    }
}
